function createFileInput(liid,lioldname,liname,fileSize){
	$('#files').html($('#files').html()+"<input type='hidden' name='fiid"+liid+"' id='fiid"+liid+"' value='"+lioldname+"'/>");
	$('#files').html($('#files').html()+"<input type='hidden' name='fiNa"+liid+"' id='fiNa"+liid+"' value='"+liname+"'/>");
	$('#files').html($('#files').html()+"<input type='hidden' name='fiSize"+liid+"' id='fiSize"+liid+"' value='"+fileSize+"'/>");
}
function openMessageBox(){
	Ext.MessageBox.show({
          msg: '文件正在上传, 请等待...',
          progressText: '上传中...',
          width:300,
          wait:true,
          waitConfig: {interval:200},
          icon:'ext-mb-download'
    });
}
function closeMessageBox(){
	Ext.MessageBox.hide();
}
function ajaxFileUpload(){
	var file = document.getElementById("uploadFile").value; 
	if(file==''){Ext.MessageBox.alert('提示', '请选择要上传的文件!');return false;}
    var filesize=file.lastIndexOf('\\');
    file=file.substring(filesize+1,file.length);
	if(alreadyUploadFile.indexOf(file)>-1){
		Ext.MessageBox.alert('提示', '此文件已上传!');
		return false;
	}else{
		openMessageBox();
		$.ajaxFileUpload({
			url:uploadUrl,
			secureuri:false,
			fileElementId:'uploadFile',
			dataType:'json',
			success: function (data, status)
			{     
				var fff=data.fileName;
				var liid=fff.substring(0,fff.lastIndexOf("."));
				Ext.MessageBox.hide();
				if(data.oldFileName!='false'){
					Ext.MessageBox.alert('提示', "文件上传成功!");
					createFileInput(liid,data.fileName,data.oldFileName,data.fileSize);
					alreadyUploadFile=alreadyUploadFile+data.oldFileName;
					$('#uploadList').html($('#uploadList').html()+"<li id='"+liid+"'>"+data.oldFileName+"<span onclick='isDelete(\""+data.fileName+"\")' style='color: #999999;cursor:hand'>删除</span></li>");
				}else{
					Ext.MessageBox.alert('提示', data.fileName);
				}
			},
			error: function (data, status, e)
			{
				Ext.MessageBox.hide();
				Ext.MessageBox.alert('提示', '上传文件异常!');
			}
		});
	}
}
function isDelete(fileName){
	deleteFile=fileName;
	var deleteFileName=$("#fiNa"+fileName.substring(0,fileName.lastIndexOf("."))).val();
	alreadyUploadFile=alreadyUploadFile.replace(deleteFileName,'');
	Ext.MessageBox.confirm('提示', '您确认删除数据?数据删除后将不可回复!', showResult);
} 
function showResult(btn){
	if(btn=='yes')ajaxFileDelete(deleteFile);
};
function ajaxFileDelete(fileName){
	$.getJSON(deteleFileUrl,{
		file: fileName
		}
		,function(json){
		var fff=json.fileName;
	    var liid=fff.substring(0,fff.lastIndexOf("."));
		$("#"+liid).remove(); 
		$("#fiid"+liid).remove();
		$("#fiNa"+liid).remove();
		$("#fiSize"+liid).remove();
		Ext.MessageBox.alert('提示信息', json.msg);
	});
} 